Add option group support for help output#7
Merged
Merged
Conversation
Flags can now be organized under named group headings (e.g., "Global
Options:") via three mechanisms with clear precedence:
1. InGroup() option on FromStruct call (highest)
2. `group:"..."` tag on embedded struct field
3. `_ struct{} \`group:"..."\`` self-declaration inside a struct
Also adds FlagSet.Group() for programmatic use and extracts shared flag
rendering into WriteFlagHelp() to eliminate duplication between ShowHelp
and dispatcher.showCommandHelp.
phinze
approved these changes
Feb 11, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
InGroup()option onFromStructcall (highest)group:"..."tag on embedded struct field_ struct{}group:"..."`` self-declaration inside a structFlagSet.Group()method for programmatic (non-struct) groupingWriteFlagHelp(), eliminating duplication betweenShowHelp()anddispatcher.showCommandHelp()Test plan
TestFromStructSelfDeclaredGroup—_ struct{}assigns group to all flagsTestFromStructWithGroup—InGroup()assigns group to all flagsTestFromStructEmbeddedGroupTag—grouptag on embedded struct assigns groupTestGroupPrecedence—InGroup()> embedded tag > self-declarationTestGroupHelpOutput— named groups render before default "Options:"TestGroupBackwardCompatibility— no groups = single "Options:" headingTestGroupMethodProgrammatic—Group()API works for non-struct usageTestGroupOrderPreserved— groups appear in insertion order, not alphabeticalTestShowHelpWithGroups— fullShowHelp()integration with groups